package com.woniu.user.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.woniu.user.dto.AddressDTO;
import com.woniu.user.pojo.Address;
import com.woniu.user.vo.AddressVO;
import com.woniu.user.vo.UserLoginVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * <p>
 * 地址表 Mapper 接口
 * </p>
 *
 * @author hushunlai
 * @since 2023-05-22
 */
public interface AddressMapper extends BaseMapper<Address> {

    Boolean addAddress(@Param("addressDTO") AddressDTO addressDTO, @Param("userId") Integer userId);

    @Select("select id, mobile, name, province, city, county, detail, is_default from t_address where user_id = #{userId}")
    @ResultType(AddressVO.class)
    List<AddressVO> listAddress(Integer userId);

    Boolean updateAddress(@Param("addressDTO") AddressDTO addressDTO, @Param("userId") Integer userId);

    @Delete("delete from t_address where id = #{addressId} and user_id = #{userId}")
    Boolean deleteAddress(@Param("addressId") Integer addressId, @Param("userId") Integer userId);

    @Select("select mobile, name, province, city, county, detail, area_code, postal_code, is_default, user_id, is_deleted, create_time, update_time from t_address where id = #{addressId}")
    Address getAddress(Integer addressId);

    @Select("select id, mobile, name, province, city, county, detail, is_default from t_address where user_id = #{userId} and is_default = 1")
    @ResultType(AddressVO.class)
    AddressVO getDefaultAddress(Integer userId);
}
